home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / lang / FPL_v147.lha / fpl / src / script.h < prev    next >
C/C++ Source or Header  |  1996-08-04  |  49KB  |  1,364 lines

  1. /******************************************************************************
  2.  *                   FREXX PROGRAMMING LANGUAGE                  *
  3.  ******************************************************************************
  4.  
  5.  script.h
  6.  
  7.  Script structures and defines!
  8.  
  9.  *****************************************************************************/
  10.  
  11. /************************************************************************
  12.  *                                                                      *
  13.  * fpl.library - A shared library interpreting script langauge.         *
  14.  * Copyright (C) 1992-1994 FrexxWare                                    *
  15.  * Author: Daniel Stenberg                                              *
  16.  *                                                                      *
  17.  * This program is free software; you may redistribute for non          *
  18.  * commercial purposes only. Commercial programs must have a written    *
  19.  * permission from the author to use FPL. FPL is *NOT* public domain!   *
  20.  * Any provided source code is only for reference and for assurance     *
  21.  * that users should be able to compile FPL on any operating system     *
  22.  * he/she wants to use it in!                                           *
  23.  *                                                                      *
  24.  * You may not change, resource, patch files or in any way reverse      *
  25.  * engineer anything in the FPL package.                                *
  26.  *                                                                      *
  27.  * This program is distributed in the hope that it will be useful,      *
  28.  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
  29.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                 *
  30.  *                                                                      *
  31.  * Daniel Stenberg                                                      *
  32.  * Ankdammsgatan 36, 4tr                                                *
  33.  * S-171 43 Solna                                                       *
  34.  * Sweden                                                               *
  35.  *                                                                      *
  36.  * FidoNet 2:201/328    email:dast@sth.frontec.se                       *
  37.  *                                                                      *
  38.  ************************************************************************/
  39.  
  40. #define OUTDATE_OLD /* to outdate the old error enums! */
  41.  
  42. #include "config.h"
  43.  
  44. #include <string.h>
  45. #include "FPL.h"
  46. #if defined(AMIGA) && defined(SHARED)
  47. #include "LibAlloc.h" /* stack allocation routines */
  48. #endif
  49.  
  50. /**********************************************************************
  51.  *
  52.  * Global defines:
  53.  *
  54.  *********************************************************************/
  55.  
  56. #ifndef  TRUE
  57. #define  TRUE    1
  58. #endif
  59. #ifndef  FALSE
  60. #define  FALSE    0
  61. #endif
  62.  
  63. #define FPLTEXT_UNKNOWN_PROGRAM "<unknown program>"
  64. /* When requesting the name of a program, and no program is available or no
  65.    name has been given. This string will be returned! */
  66.  
  67. #define MAX_DIMS         40  /* Maximum number of array dimensions */
  68. #define IDENTIFIER_LEN       64
  69. /* maximum number of characters in a function-, variable- or label name
  70.    ANSI C Standard X3J11 states that there should be at least "31
  71.    significant initial characters in an internal identifier or a macro name" */
  72. #define ADDSTRING_DEFAULT     16  /* default length of a string expression */
  73. #define ADDSTRING_INC         63  /* string expression length increase step */
  74. #define MAX_ARGUMENTS         63  /* number of parsed function arguments
  75.                      before realloc is done */
  76.  
  77. #define FPL_HASH_SIZE 67
  78. /* Default hash table size. This should not be dividable with 2, 3, 4 or 5 */
  79.  
  80. #define FPL_MIN_HASH 10
  81. /* The smallest acceptable hash table size */
  82.  
  83. #define BUF_SIZE (IDENTIFIER_LEN+3) /* "global" FPL buffer size */
  84.  
  85. #if defined(AMIGA) && defined(SHARED)
  86. #define FPL_MIN_STACK 8000  /* smallest required stack */
  87. #define FPL_MAX_STACK 20000 /* maximum stack left after a run */
  88. #define FPL_MAX_LIMIT 40000 /* default maximum stack use possible */
  89.  
  90. #define FPLSTACK_MINIMUM 1000 /* Stack margin. When the stack space is below,
  91.                  this, than realloc to a bigger one! */
  92. #endif
  93.  
  94. #define BLOCK_ENTRIES 16    /* Number of free-block entries in the
  95.                    free-block array */
  96. #define MEMORY_QUEUE_SIZE 20    /* number of free blocks in the queue */
  97.  
  98. #define MEMORY_QUEUE    1    /* Yes, we'll use the memory queuing system! */
  99.  
  100. #define ALLOCBIT    (1<<31) /* set if MALLOC_STATIC */
  101. #define SIZEBITS    ~ALLOCBIT
  102.  
  103. #ifdef DEBUG
  104. #define MEMORY_COOKIE    0    /* When using the DEBUG option, all Malloc()
  105.                    will allocate a number of extra bytes at
  106.                    the end of the block. These will be checked
  107.                    to be intact when the block is freed or
  108.                    CheckMem()'ed. This #define tells the size
  109.                    of that block! */
  110.  
  111. #define PRE_COOKIE    0    /* Makes all allocations allocate this many
  112.                    bytes extra before the block! */
  113.  
  114. #define DEBUGPARAMETERS1 , AREG(1) uchar *source, DREG(2) long line
  115. #define DEBUGPARAMETERS2 , uchar *source, long line
  116.  
  117.  
  118. #else
  119. #define MEMORY_COOKIE 0
  120. #endif
  121.  
  122. /*
  123.  * Flags to use with the exists() function:
  124.  */
  125. #define EXISTS_FUNCTION 'f'
  126. #define EXISTS_VARIABLE 'v'
  127. #define EXISTS_STRING   's'
  128. #define EXISTS_INTEGER  'i'
  129.  
  130. /**********************************************************************
  131.  *
  132.  * Different character defines:
  133.  *
  134.  **********************************************************************/
  135.  
  136. #define _U (1<<0)  /* upper case */
  137. #define _L (1<<1)  /* lower case */
  138. #define _W (1<<2)  /* also included as a valid identifier character */
  139. #define _N (1<<3)  /* numerical digit 0-9 */
  140. #define _S (1<<4)  /* white space */
  141. #define _C (1<<5)  /* control character */
  142. #define _P (1<<6)  /* punctation characters */
  143. #define _X (1<<7)  /* hexadecimal digit */
  144.  
  145. extern const uchar type[257];
  146.  
  147. #define CHAR_OPEN_BRACE    '{'
  148. #define CHAR_CLOSE_BRACE   '}'
  149. #define CHAR_OPEN_PAREN    '('
  150. #define CHAR_CLOSE_PAREN   ')'
  151. #define CHAR_OPEN_BRACKET  '['
  152. #define CHAR_CLOSE_BRACKET ']'
  153. #define CHAR_COMMA         ','
  154. #define CHAR_SEMICOLON     ';'
  155. #define CHAR_PLUS          '+'
  156. #define CHAR_MINUS         '-'
  157. #define CHAR_ONCE_COMPLEMENT '~'
  158. #define CHAR_NOT_OPERATOR  '!'
  159. #define CHAR_MULTIPLY      '*'
  160. #define CHAR_DIVIDE        '/'
  161. #define CHAR_AND           '&'
  162. #define CHAR_OR            '|'
  163. #define CHAR_XOR           '^'
  164. #define CHAR_REMAIN        '%'
  165. #define CHAR_QUESTION      '?'
  166. #define CHAR_COLON         ':'
  167. #define CHAR_ASSIGN        '='
  168. #define CHAR_LESS_THAN     '<'
  169. #define CHAR_GREATER_THAN  '>'
  170. #define CHAR_SPACE         ' '
  171. #define CHAR_DOLLAR       '$'
  172. #define CHAR_HASH       '#'
  173. #define CHAR_ZERO          '0'
  174. #define CHAR_ONE           '1'
  175. #define CHAR_TWO           '2'
  176. #define CHAR_THREE         '3'
  177. #define CHAR_FOUR          '4'
  178. #define CHAR_FIVE          '5'
  179. #define CHAR_SIX           '6'
  180. #define CHAR_SEVEN         '7'
  181. #define CHAR_EIGHT         '8'
  182. #define CHAR_NINE          '9'
  183. #define CHAR_UPPER_A       'A'
  184. #define CHAR_A             'a'
  185. #define CHAR_UPPER_B       'B'
  186. #define CHAR_B             'b'
  187. #define CHAR_UPPER_C       'C'
  188. #define CHAR_C             'c'
  189. #define CHAR_D             'd'
  190. #define CHAR_F             'f'
  191. #define CHAR_UPPER_I       'I'
  192. #define CHAR_I             'i'
  193. #define CHAR_UPPER_N       'N'
  194. #define CHAR_N             'n'
  195. #define CHAR_O             'o'
  196. #define CHAR_R             'r'
  197. #define CHAR_UPPER_S       'S'
  198. #define CHAR_S             's'
  199. #define CHAR_T             't'
  200. #define CHAR_V             'v'
  201. #define CHAR_UPPER_X       'X'
  202. #define CHAR_X             'x'
  203. #define CHAR_APOSTROPHE    '\''
  204. #define CHAR_NEWLINE       '\n'
  205. #define CHAR_VERTICAL_TAB  '\v'
  206. #define CHAR_CARRIAGE_RETURN '\r'
  207. #define CHAR_ALERT         '\a'
  208. #define CHAR_QUOTATION_MARK '\"'
  209. #define CHAR_BACKSLASH     '\\'
  210. #define CHAR_FORMFEED      '\f'
  211. #define CHAR_BACKSPACE     '\b'
  212. #define CHAR_TAB           '\t'
  213. #define CHAR_ASCII_ZERO    '\0'
  214.  
  215. #define CASE_BIT  ('a'-'A')
  216.  
  217. /**********************************************************************
  218.  *
  219.  * A bunch of useful enums:
  220.  *
  221.  **********************************************************************/
  222.  
  223. typedef enum {          /* all FPL operators */
  224.   OP_NOTHING, OP_PLUS, OP_MINUS, OP_DIVISION, OP_MULTIPLY,  OP_SHIFTL,
  225.   OP_SHIFTR, OP_REMAIN, OP_BINAND, OP_BINOR, OP_BINXOR, OP_LOGAND,
  226.   OP_LOGOR, OP_COMPL, OP_COND1, OP_COND2, OP_EQUAL, OP_LESSEQ, OP_GRETEQ,
  227.   OP_LESS, OP_GRET, OP_NOTEQ, OP_NOT,
  228.  
  229.   OP_PREINC, /* pre increment */
  230.   OP_PREDEC  /* pre decrement */
  231. #ifdef NEXT_GENERATION
  232.     , OP_COMMA, OP_ASSIGN, OP_PLUSASSIGN, OP_MINUSASSIGN,
  233.     OP_ORASSIGN, OP_XORASSIGN, OP_ANDASSIGN, OP_LSHIFTASSIGN, OP_RSHIFT_ASSIGN,
  234.     OP_REMAINASIGN, OP_MULASSIGN
  235. #endif
  236.     } Operator;
  237.  
  238. typedef enum { /* the internal functions and keywords */
  239.   CMD_AUTO=-200,
  240.   CMD_BREAK,
  241.   CMD_CASE,
  242.   CMD_CONST,
  243.   CMD_CONTINUE,
  244.   CMD_DEFAULT,
  245.   CMD_DO,
  246.   CMD_DOUBLE,
  247.   CMD_ENUM,
  248.   CMD_EXIT,
  249.   CMD_EXPORT,
  250.   CMD_FLOAT,
  251.   CMD_FOR,
  252.   CMD_IF,
  253.   CMD_INT,
  254.   CMD_REGISTER,
  255.   CMD_RESIZE,
  256.   CMD_RETURN,
  257.   CMD_SIGNED,
  258.   CMD_STATIC,
  259.   CMD_STRING,
  260.   CMD_STRUCT,
  261.   CMD_SWITCH,
  262.   CMD_TYPEDEF,
  263.   CMD_UNION,
  264.   CMD_UNSIGNED,
  265.   CMD_VOID,
  266.   CMD_VOLATILE,
  267.   CMD_WHILE,
  268.  
  269.   FNC_ABS=-100,
  270.   FNC_ATOI,
  271.   FNC_DEBUG,
  272.   FNC_EVAL,
  273.   FNC_EXISTS,
  274.   FNC_INTERPRET,
  275.   FNC_ITOA,
  276.   FNC_ITOC,
  277.   FNC_JOINSTR,
  278.   FNC_LTOSTR,
  279.   FNC_RENAME,
  280.   FNC_SPRINTF,
  281.   FNC_SSCANF,
  282.   FNC_STRCMP,
  283.   FNC_STRICMP,
  284.   FNC_STRISTR,
  285.   FNC_STRLEN,
  286.   FNC_STRNCMP,
  287.   FNC_STRNICMP,
  288.   FNC_STRSTR,
  289.   FNC_STRTOL,
  290.   FNC_SUBSTR,
  291.   FNC_OPENLIB, /* amiga only */
  292.   FNC_CLOSELIB, /* amiga only */
  293.  
  294.   LAST_INTERNAL /* must be the last of these ones! */
  295.   } Funcs;
  296.  
  297. #define KEYWORD_ELSE "else" /* the "else" keyword define !! */
  298.  
  299. /**********************************************************************
  300.  *
  301.  * Compile macro defines.
  302.  *
  303.  *********************************************************************/
  304.  
  305. #define P_LONG  scr->text += sizeof(long) /* pass a 'long' */
  306. #define P_SHORT scr->text += sizeof(short) /* pass a 'short' */
  307. #define GETLONG  (*(long *)scr->text)  /* get a long */
  308. #define GETSHORT (*(short *)scr->text) /* get a short */
  309.  
  310. /**********************************************************************
  311.  *
  312.  * Debug macro defines.
  313.  *
  314.  *********************************************************************/
  315.  
  316. #ifdef DEBUG
  317. /* If debugging, use the mem integer to debug the MALLOC/FREE balance! */
  318. extern long mem;
  319. extern long maxmem;
  320. #endif
  321.  
  322. /**********************************************************************
  323.  *
  324.  * Script() control bits:
  325.  *
  326.  *********************************************************************/
  327.  
  328. #define SCR_NORMAL  0   /* Nothing! */
  329. #define SCR_IF      (1<<0)
  330. #define SCR_WHILE   (1<<1)
  331. #define SCR_DO      (1<<2)
  332. #define SCR_FOR     (1<<3)
  333. #define SCR_LOOP    (SCR_WHILE|SCR_DO|SCR_FOR)
  334. #define SCR_FUNCTION (1<<4)
  335. #define SCR_BRACE   (1<<5) /* Declaration is allowed! This started with a brace -
  336.                  should end with a brace, return(), break or exit()
  337.                */
  338. #define SCR_RETURN_STRING (1<<6)/* This function is declared to return a string */
  339. #define SCR_GLOBAL (1<<7)
  340. #define SCR_SWITCH (1<<8)
  341. #define SCR_FILE   (1<<9)  /* this is the file level, on this level the program
  342.                               can end with a '\0' char! */
  343. #define SCR_DEBUG  (1<<10) /* this level runs in debug mode! */
  344.  
  345. /***********************************************************************
  346.  *
  347.  * Expression() control bits:
  348.  *
  349.  **********************************************************************/
  350.  
  351. #define CON_NORMAL     0      /* normal statement */
  352. #define CON_DECLINT    (1<<0) /* int declaration statement */
  353. #define CON_DECLSTR    (1<<1) /* string declaration statement */
  354. #define CON_GROUNDLVL  (1<<2) /* this statement starts at the ground level */
  355. #define CON_SEMICOLON  (1<<3) /* forces Statement() to return positive on ";"
  356.                  statement. Designed to support "for(;;)". */
  357. #define CON_PAREN      (1<<4) /* support for the last expression of the for(;;)
  358.                  ones */
  359. #define CON_ACTION     (1<<5) /* This flag forces Statement() to report errror
  360.                  if no "action" was made in the statement just
  361.                  parsed. */
  362. #define CON_END        (1<<6) /* Tell statement() there can be no
  363.                  "UNEXPECTED_END".*/
  364. #define CON_NUM        (1<<7) /* Only accept numerical statements! */
  365. #define CON_STRING     (1<<8) /* Hint about this being a string statement! */
  366. #define CON_DECLVOID   (1<<9) /* Declaration of a `void' function! */
  367. #define CON_DECLEXP    (1<<10) /* Declaration of an `export' symbol */
  368. #define CON_DECLGLOB   (1<<11) /* Declaration of a global symbol! */
  369. #define CON_IDENT      (1<<12) /* The local parameter points to an already
  370.                   parsed "struct Identifier" */
  371. #define CON_DECL8      (1<<13) /* Declaration of an eight bit variable */
  372. #define CON_DECL16     (1<<14) /* Declaration of an sixteen bit variable */
  373. #define CON_DECLUNSIGN (1<<15) /* Unsigned declaration */
  374. #define CON_DECLCONST  (1<<16) /* Constant declaration (read only) */
  375. #define CON_DECLSTATIC (1<<17) /* Static declaration */
  376.  
  377. #define CON_LEVELOK    (1<<18) /* Disables same "proper level" controls */
  378.  
  379. #define CON_NORETURN   (1<<19) /* Don't calculate return code, nobody wants
  380.                                   to know! */
  381.  
  382. #define CON_LESSTHAN32 (CON_DECL8|CON_DECL16)
  383. #define CON_DECLARE (CON_DECLINT|CON_DECLSTR|CON_DECLVOID) /* declaration */
  384.  
  385. /***********************************************************************
  386.  *
  387.  * A bunch of useful macros:
  388.  *
  389.  **********************************************************************/
  390.  
  391. #define isalpha(c)  ((type+1)[c] & (_U|_L))
  392. #define isupper(c)  ((type+1)[c] & _U)
  393. #define islower(c)  ((type+1)[c] & _L)
  394. #define isdigit(c)  ((type+1)[c] & _N)
  395. #define isxdigit(c) ((type+1)[c] & _X)
  396. #define isalnum(c)  ((type+1)[c] & (_U|_L|_N))
  397. #define isspace(c)  ((type+1)[c] & _S)
  398. #define ispunct(c)  ((type+1)[c] & _P)
  399. #define isprint(c)  ((type+1)[c] & (_U|_L|_N|_P))
  400. #define iscntrl(c)  ((type+1)[c] & _C)
  401. #define isascii(c)  (!((c) & ~127))
  402. #define isgraph(c)  ((type+1)[c] & (_U|_L|_N|_P))
  403. #define toascii(c)  ((c) & 127)
  404. #define toupper(c)  ((type+1)[c] & _L? c-CASE_BIT: c)
  405. #define tolower(c)  ((type+1)[c] & _U? c+CASE_BIT: c)
  406.  
  407. #define isodigit(c) ((c) >= CHAR_ZERO && (c) <= CHAR_SEVEN)
  408.  
  409. #define isident(c)  ((type+1)[c] & (_U|_L|_W))
  410. #define isidentnum(c)  ((type+1)[c] & (_U|_L|_W|_N))
  411.  
  412.   /* CALL - macro performing the instruction inside parentheses and receiving
  413.      the return code in `ret'. If `ret' happens to become non-zero, a
  414.      "return(ret);" will be performed! */
  415. #define CALL(func) if(ret=(func)) return(ret)
  416.  
  417.   /* GETMEM - macro allocating memory and returning FPLERR_OUT_OF_MEMORY if it
  418.      fails! */
  419.  
  420. #define GETMEM(var,size) if(!(var=(void *)MALLOC(size))) \
  421.   return(FPLERR_OUT_OF_MEMORY);
  422.  
  423.   /* GETMEMA - macro allocating static memory and returning FPLERR_OUT_OF_MEMORY
  424.      if it fails! */
  425.  
  426. #define GETMEMA(var,size) if(!(var=(void *)MALLOCA(size))) \
  427.   return(FPLERR_OUT_OF_MEMORY);
  428.  
  429.   /* STRDUP - macro instead of the common strdup() ! */
  430.  
  431. #define STRDUP(var, pointer) \
  432.   GETMEM(var, strlen((uchar *)(pointer))+1);\
  433.   strcpy(var, (pointer));
  434.  
  435.   /* STRDUPA - macro instead of the common strdup() for STATIC allocs ! */
  436.  
  437. #define STRDUPA(var, pointer) \
  438.   GETMEMA(var, strlen((uchar *)(pointer))+1);\
  439.   strcpy(var, (uchar *)(pointer));
  440.  
  441.   /* UPPER - returns uppercase version any a-z character */
  442. #define UPPER(x) ((x)&~CASE_BIT)
  443.  
  444.   /* ABS - returns the absolute value of the argument */
  445. #define ABS(x) ((x)>0?x:-x)
  446.  
  447.   /* MIN - returns the minimum value of the two input arguments */
  448. #define MIN(x,y) ((x)<(y)?(x):(y))
  449.  
  450.   /* MIN3 - returns the minimum value of the three input arguments */
  451. #define MIN3(x,y,z) MIN( MIN((x),(y)) ,(z))
  452.  
  453.   /* Here follows the define for strdup() of a string stored in a
  454.      (struct fplStr *) */
  455. #define STRFPLDUP(dest,source)\
  456.    do {\
  457.      GETMEM(dest, sizeof(struct fplStr)+source->len); /* get string space */\
  458.      memcpy(dest->string, source->string, source->len); /* copy string */\
  459.      dest->len=dest->alloc=source->len; /* set alloc and length */\
  460.      dest->string[dest->len]='\0'; /* zero terminate! */\
  461.    } while(0)
  462.  
  463.  
  464. #define ASSIGN_OPERATOR ( \
  465.              (scr->text[0]==CHAR_ASSIGN &&        \
  466.               scr->text[1]!=CHAR_ASSIGN) ||        \
  467.              ((scr->text[0]==CHAR_PLUS ||        \
  468.               scr->text[0]==CHAR_MINUS ||        \
  469.               scr->text[0]==CHAR_MULTIPLY ||    \
  470.               scr->text[0]==CHAR_DIVIDE ||        \
  471.               scr->text[0]==CHAR_AND ||        \
  472.               scr->text[0]==CHAR_OR ||        \
  473.               scr->text[0]==CHAR_REMAIN ||        \
  474.               scr->text[0]==CHAR_XOR) &&        \
  475.              scr->text[1]==CHAR_ASSIGN) ||        \
  476.              !strncmp("<<=", scr->text, 3) ||    \
  477.              !strncmp(">>=", scr->text, 3)        \
  478.             )
  479.  
  480.  /* Get-file-date macros */
  481.  
  482. #ifdef AMIGA
  483. #define GETFILEDATE(x) (x.fib_Date.ds_Days * 86400 +\
  484.                         x.fib_Date.ds_Minute * 60 +\
  485.                         x.fib_Date.ds_Tick / TICKS_PER_SECOND)
  486. #define timeoffile(date,file)                                  \
  487.       do {                                                     \
  488.         struct MyLibrary *lib = (struct MyLibrary *)getreg(REG_A6); \
  489.         struct Library *DOSBase = lib->ml_DosBase;             \
  490.         register BPTR lock;                                    \
  491.         struct FileInfoBlock fi;                               \
  492.         date =0;                                               \
  493.         if (lock=(BPTR)Lock((UBYTE *)(file), ACCESS_READ)) {   \
  494.           if (Examine((BPTR)lock, &fi))                        \
  495.             date = GETFILEDATE(fi);                            \
  496.           UnLock((BPTR)lock);                                  \
  497.         }                                                      \
  498.       } while(0)
  499. #else
  500. #define timeoffile(date,file)                                  \
  501.       do {                                                     \
  502.         struct stat statstr;                                   \
  503.     date = !stat(prog->name, &statstr)?statstr.st_mtime:0; \
  504.       } while(0)
  505. #endif
  506.  
  507. /***********************************************************************
  508.  *
  509.  * Defines:
  510.  *
  511.  **********************************************************************/
  512.  
  513. #define MALLOC_DYNAMIC 0
  514. #define MALLOC_STATIC  1
  515.  
  516. #define FREE_KIND(x) FreeKind(scr, (void *)(x))
  517.  
  518. #ifdef DEBUG
  519. #define MALLOC(x) MallocCycle(scr, x, __FILE__, __LINE__)
  520. #define MALLOCA(x) Malloc(scr, (x), MALLOC_STATIC, __FILE__, __LINE__)
  521. #else
  522. #define MALLOC(x) MallocCycle(scr, x)
  523. #define MALLOCA(x) Malloc(scr, (x), MALLOC_STATIC)
  524. #endif
  525.  
  526. #define FREE(x) FreeCycle(scr, (void *)(x))
  527. #define FREEA(x) Free(scr, (void *)(x), MALLOC_STATIC)
  528.  
  529. #define FREEALL() FreeAll(scr, MALLOC_DYNAMIC)
  530. #define FREEALLA() FreeAll(scr, MALLOC_STATIC)
  531.  
  532. /* old version:
  533.    #define GETSTRLEN(str) ((long)*(long *)(str))
  534.    */
  535. #define GETSTRLEN(str) (((struct fplStr *)(((uchar *)str)-offsetof(struct fplStr, string)))->len)
  536.  
  537. #if defined(AMIGA)
  538.   /*
  539.    * We have to make all external referenced functions to receive the
  540.    * parameters in certain registers and restore the A4 register.
  541.    */
  542.  
  543. #define PREFIX __asm __saveds   /* special SAS/C ideas! Forces arguments
  544.                    to be puched in specified registers and
  545.                    forces the A6 register to be loaded at the
  546.                    beginning of the funtion. */
  547. #define AREG(x) register __a ## x
  548. #define DREG(x) register __d ## x
  549. #define REGARGS __regargs
  550. #define ASM __asm
  551.  
  552.  /***************************************
  553.   *
  554.   * funclib specific defines:
  555.   *
  556.   **************************************/
  557.  
  558. #define FPLLIB_SOURCE "FPLLIBS:"
  559. #define FPLLIB_OPENCMD "open "
  560. #define FPLLIB_CLOSECMD "close "
  561. #define FPLLIB_MAXSPACE 60 /* length of the command string */
  562.  
  563. #else
  564.   /*
  565.    * No need for any of those!
  566.    */
  567. #define PREFIX
  568. #define REGARGS
  569. #define AREG(x)
  570. #define DREG(x)
  571. #define ASM
  572. #endif
  573.  
  574. #if defined(AMIGA) /* the amiga library defines... */
  575. #define INLINE __inline
  576. #else
  577. #define INLINE
  578. #endif
  579.  
  580. /**********************************************************************
  581.  *
  582.  * Create some structures and define their flags:
  583.  *
  584.  *********************************************************************/
  585.  
  586. struct Unary {
  587.   Operator unary;
  588.   struct Unary *next;
  589. };
  590.  
  591. struct InsideFunction {
  592.   /*
  593.    * Used for `inside' functions.
  594.    */
  595.  
  596.   uchar ret;
  597.   uchar *format; 
  598.   
  599.   long col; /* column number of the inside function position. */
  600.   long prg; /* line number of the function */
  601.   uchar *file; /* name of file where this function resides */
  602.   long virprg; /* virtual line number */
  603.   uchar *virfile; /* virtual file name */
  604. };
  605.  
  606. struct ExternalFunction {
  607.   /*
  608.    * Used for all other functions and keywords.
  609.    */
  610.   uchar ret; /* 'I' - returns an integer
  611.            'S' - returns a string
  612.            */
  613.   uchar *format; /* Parameter format. Zero terminated. Unlimited length.
  614.            'I' - integer
  615.            'S' - string
  616.            'C' - string variable structure
  617.            'N' - integer variable structure
  618.            '>' - variable number of the previous type.
  619.  
  620.            NULL pointer - no argument at all.
  621.            lower case - optional (must only be to the right of
  622.            the required)
  623.              
  624.            Ex: "ISsc"
  625.            means that the function requires two parameters:
  626.            one integer and one string. It has two optional
  627.            parameters: one string and one string variable. */
  628.   long ID; /* Identifier ID. This information is sent in the
  629.           fplArgument structure.
  630.           <0 is reserved for FPL internals. */
  631.  
  632.   void *data; /* function specific data! */
  633.   long (*func)(void *); /* optional function! */
  634. };
  635.  
  636. struct fplStr {
  637.   /*
  638.    * FPL 'string' structure!
  639.    */
  640.   long alloc;     /* Allocated length of following string. That goes for the
  641.              string *only*! The structure's size have to be added if
  642.              the entire alloc is wanted! Notice that the first (or
  643.              last) byte in the string belongs to the structure and
  644.              not the 'string'!!! */
  645.   long len;      /* length of following string */
  646.   uchar string[1]; /* memory included in the string! */
  647. };
  648.  
  649.  
  650. struct fplVariable {
  651.   struct Identifier *ref; /* Used when passing variable references. */
  652.                           /* pointer to the "actual" identifier */
  653.  
  654.   long *dims;  /* An array holding the size of each dimension. */
  655.   long num;    /* Number of dimensions */
  656.   long size;   /* Number of variables in this array, that it is all
  657.           dims' members multiplied with each other! */
  658.  
  659.   long ID; /* set when using EXTERNAL_VARIABLEs from v10 */
  660.  
  661.   /*
  662.    * Variable values to read. This is an array of values if the variable
  663.    * was declared as an array!
  664.    */
  665.   union {
  666.     struct fplStr **str; /* FPL string  */
  667.     long *val32;    /* FPL integer */
  668.     short *val16;    /* FPL short   */
  669.     uchar *val8;    /* FPL char    */
  670.     void *val;        /* general FPL data pointer */
  671.   } var;
  672. };
  673.  
  674. struct Identifier {
  675.   /* This structure is used to store all identifiers in when they are "hashed
  676.      in". Notice that *ALL* data in this structure is pointing and referring
  677.      to the very same data as was sent to it, which means that you must keep
  678.      that data intact while using FPL. */
  679.  
  680.   uchar *name; /* Identifier. Must be absolutely unique and not more than
  681.                   MAX_COMMAND_LEN characters long. */
  682.  
  683.   union {
  684.     struct ExternalFunction external;
  685.     struct InsideFunction inside;
  686.     struct fplVariable variable;
  687.   } data;
  688.   
  689.   unsigned long flags; /* See below! */
  690.  
  691.   uchar *file;    /* file name of the file in which we find this identifier */
  692.   
  693.   struct Identifier *func; /* It exists only under this function. Pointer might
  694.                   be NULL if in no function! */
  695.  
  696.   long level; /* In which level this exists.
  697.          Variables exist in all levels below (with a higher number)
  698.          where it was declared. Two declarations using the same
  699.          name in the same level is not allowed!
  700.          LONG_MAX if global! */
  701.   
  702.   unsigned long hash; /* Hash value. To get the proper hash table entry for
  703.              this, use [hash%HASH_TABLE_SIZE] */
  704.   
  705.   /* Bidirectional links to keep a hash value sorted order among
  706.      functions using the same hash table entry: */
  707.   struct Identifier *prev;
  708.   struct Identifier *next;
  709. };
  710.  
  711. /****** Identifier.flags defines:  ******/
  712.  
  713. /* Data type */
  714.  
  715. #define FPL_STRING_VARIABLE   (1<<0)  /* string variable */
  716. #define FPL_INT_VARIABLE      (1<<1)  /* integer variable */
  717. #define FPL_REFERENCE         (1<<2)  /* identifier reference */
  718. #define FPL_INTERNAL_FUNCTION (1<<3)  /* internal FPL function */
  719. #define FPL_EXTERNAL_FUNCTION (1<<4)  /* user supplied external function */
  720. #define FPL_INSIDE_FUNCTION   (1<<5)  /* inside function in any program */
  721. #define FPL_KEYWORD          (1<<6)  /* this is a keyword identifier! */
  722. #define FPL_KEYWORD_DECLARE   (1<<7)  /* declaring keyword */
  723. #define FPL_INSIDE_NOTFOUND   (1<<8)  /* This inside function has not been
  724.                      discovered yet. The position the
  725.                      data points to is the search start
  726.                      position. */
  727. #define FPL_IGNORE            (1<<9) /* Read this and then drop it! */
  728. /* Data status */
  729.  
  730. #define FPL_READONLY          (1<<10) /* const variable! */
  731. #define FPL_EXTERNAL_VARIABLE (1<<11) /* external variable! new from V10 */
  732. #define FPL_EXPORT_SYMBOL     (1<<12) /* cross program accessible */
  733. #define FPL_GLOBAL_SYMBOL     (1<<13) /* global accessible in one file */
  734. #define FPL_SHORT_VARIABLE    (1<<14) /* short (16-bit) variable */
  735. #define FPL_CHAR_VARIABLE     (1<<15) /* char (8-bit) variable */
  736. #define FPL_UNSIGNED_VARIABLE (1<<16) /* unsigned variable */
  737. #define FPL_STATIC_VARIABLE   (1<<17) /* static variable! */
  738.  
  739. #define FPL_DEALLOC_NAME_ANYWAY (1<<18) /* In normal cases, this name should
  740.                                            not get freed, but this is not a
  741.                                            normal case... ;-P */
  742. #define FPL_COMPILER_ADDED    (1<<19)    /* added by a compiled program */
  743.  
  744. #define FPL_STATUS (FPL_READONLY|FPL_HIJACKED_VARIABLE|FPL_EXPORT_SYMBOL\
  745.             FPL_GLOBAL_SYMBOL|FPL_SHORT_VARIABLE|FPL_CHAR_VARIABLE\
  746.             FPL_UNSIGNED_VARIABLE|FPL_STATIC_VARIABLE|FPL_REFEREMCE)
  747.  
  748. /*
  749.  * These two lower flags should be combined with the "Data status" flags
  750.  * when declaring variables!
  751.  */
  752.  
  753. #define FPLDECL_STRING          (1<<31) /* Keyword declaring string */
  754. #define FPLDEC_INT          (1<<30) /* Keyword declaring int */
  755.  
  756.  
  757. #define FPL_VARIABLE_LESS32 (FPL_SHORT_VARIABLE|FPL_CHAR_VARIABLE)
  758. #define FPL_VARIABLE (FPL_STRING_VARIABLE|FPL_INT_VARIABLE)
  759. #define FPL_FUNCTION (FPL_INTERNAL_FUNCTION|FPL_EXTERNAL_FUNCTION |\
  760.               FPL_INSIDE_FUNCTION)
  761.  
  762. /***** Identifier.ID defines: ******/
  763.  
  764. struct Position {
  765.   /*
  766.    * This struct should be used from now on when storing and using the
  767.    * interpret position!
  768.    */
  769.   uchar *text;       /* Current interpret position */
  770.   long prg;         /* Current line number */
  771.   uchar *virfile;    /* virtual file name pointer */
  772.   long virprg;        /* virtual line number */
  773. };
  774.  
  775.  
  776. #define FPL_INSIDE_FUNCTION_ID -3;
  777.  
  778. struct Condition {
  779.   uchar *bracetext;  /* pointer to the character to the right of the open
  780.                brace */
  781.   long braceprg;    /* line number of the above data */
  782.   uchar *check;      /* pointer to the expression. Used by while() and for() */
  783.   long checkl;      /* the line number of the expression */
  784.   uchar *postexpr;   /* USED BY "for" : pointer to statement3 */
  785.   long postexprl;   /* USED BY "for" : statement3's line number */
  786. };
  787.  
  788. struct Expr {  /* the numerical expression linked list */
  789.   union {
  790.     long val;        /* numerical return */
  791.     struct fplStr *str; /* string return */
  792.   } val;
  793.   Operator operator;  /* see the operator enums! */
  794.   struct Unary *unary; /* unary/primary operators linked list! */
  795.   short flags;          /* see below */
  796.   struct Expr *next; 
  797. };
  798.  
  799. /**** struct Expr.flags defines: ****/
  800. #define FPL_STRING     (1<<0) /* Expr structure is a string. */
  801. #define FPL_NOFREE     (1<<1) /* A returned string should not be freed */
  802. #define FPL_OPERAND    (1<<2) /* Next part in the expression is a operand */
  803. #define FPL_ACTION     (1<<3) /* The expression includes any variable change(s) */
  804. #define FPL_BREAK      (1<<4) /* The val member specifies number of levels
  805.                  left to break from! */
  806. #define FPL_RETURN     (1<<5) /* There is a return call received, return to the
  807.                  last function caller. */
  808. #define FPL_CONTINUE   (1<<6) /* Continue is flagged! */
  809.  
  810. #define FPL_DEFUNCTION (1<<7) /* The Expression() just called declared AND
  811.                  defined a function! */
  812. #define FPL_BRACE      (1<<8) /* This invoke returned due to a closing brace! */
  813.  
  814. struct Local {
  815.   /*
  816.    * This structure will create a linked list of all local variables declared
  817.    * in this level. When leaving this level, *ALL* variables with the names
  818.    * that the ->ident member points to must be deleted, using DelIdentifier().
  819.    */
  820.   struct Identifier *ident;
  821.         /* This pointer points to the Identifier structure,
  822.            that means this should *NOT* be freed individually
  823.            but only the entire structure and the Identifier structure
  824.            (and members) at the same time! */
  825.   struct Local *next; /* Next member in this chain */
  826. };
  827.  
  828. /*
  829.  * All fplFunction ID's below zero are reserved for FPL internal use.
  830.  * We use the funcdata member to set some flags:
  831.  */
  832. #define FPL_HASH_INSIDE   1
  833. #define FPL_HASH_INTERNAL 2
  834.  
  835. struct CompiledInfo {
  836.   struct Identifier **list; /* the identifier pointer list */
  837.   long listentries; /* amount of identifiers in the list */
  838.   long listsize;    /* allocated size of the list */
  839. #define DEFAULT_LISTSIZE 32 /* allocate sybol list with this step */
  840. };
  841.  
  842. struct Program {
  843.   struct Program *next;
  844.   uchar *name;        /* unique name of program */
  845.   long running;        /* true if running */
  846.   long openings;    /* number of invokes! */
  847.   uchar *program;    /* program pointer or NULL if not present in memory */
  848.   long lines;        /* number of lines */
  849.   long size;        /* total size in number of bytes */
  850.   long flags;        /* see defines below */
  851.  
  852.   long date;        /* date in seconds (system dependent) */
  853.  
  854.   char foundstart;    /* this program's "main" function is found! */
  855.   long startcol;    /* Where "main" started. Column number */
  856.   long startprg;    /* Where "main" started. Line number */
  857.   long virprg;        /* Virtual line number of "main" */
  858.   uchar *virfile;    /* virtual file name of "main" */
  859.   long column;        /* Last interpreted column!
  860.                _ONLY_ to read if this program isn't opened! */
  861.   long warnings;    /* number of warnings found in this file! */
  862.  
  863.   long index;           /* where the execution starts */
  864.   struct CompiledInfo globalinfo; /* global symbol list for this program */
  865. };
  866.  
  867. /* Program.flags: */
  868. #define PR_USERSUPPLIED (1<<0)
  869. /* This program is user supplied. That means that FPL has *not* allocated the
  870.    memory this program uses, making no straight flushes allowed! */
  871.  
  872. #define PR_CACHEFILE (1<<1)
  873. /* This program should be cached until anything else is said! */
  874.  
  875. #define PR_FILENAMEFLUSH (1<<2)
  876. #define PR_NAME_IS_FILENAME PR_FILENAMEFLUSH
  877. /* When this program is flushed, it can always be restored by using the
  878.    program name as file name to read from! */
  879.  
  880. #define PR_TEMPORARY (1<<3)
  881. /* This isn't a real program but only created for a temporary usage reason! */
  882.  
  883. #define PR_GLOBALSTORED (1<<4)
  884. /* This program has got it's global symbols stored! */
  885.  
  886. #define PR_CACHEEXPORTS (1<<5)
  887. /* This program should be cached only if exports are declared */
  888.  
  889. #define PR_FLUSH_NOT_IN_USE (1<<6)
  890. /* This program should be flushed from memory when not in use, to save system
  891.    memory! */
  892.  
  893. #define PR_REREAD_CHANGES (1<<7)
  894. /* This program should be re-read into memory if accessed and the actual file
  895.    on disk has changed! */
  896.    
  897. #define PR_KIDNAP_CACHED (1<<8)
  898. /* This program should get kidnapped if it is PR_USERSUPPLIED and should get
  899.    cached! */
  900.  
  901. #define PR_COMPILED (1<<9)
  902. /* This program is compiled! */
  903.  
  904. #define PR_SELECTED_FPC (1<<10)
  905. /* The .FPC extention program was found newer than the .FPL and thus
  906.    loaded and used (even though the .FPL extension will be displayed in
  907.    order to know */
  908.  
  909. struct FuncList {
  910.   /*
  911.    * This struct is a general purpose linked list struct for keeping track
  912.    * of a list of char pointers.
  913.    */
  914.   struct FuncList *next;
  915.   long opens;
  916.   uchar flags;
  917.   uchar *name;
  918. };
  919.  
  920. struct Store {
  921.   /*
  922.    * This is all data that should be backuped when recursing, and
  923.    * restored when the recursing function ends.
  924.    */
  925.   uchar *text;
  926.   long prg;
  927.   uchar strret;
  928.   long level;
  929.   long varlevel;
  930.   uchar *virfile;
  931.   long virprg;
  932.   uchar *interpret;
  933.   struct Local *globals;
  934.   struct fplMsg *msg;
  935.   struct Program *prog;
  936.   struct Local *locals;
  937. };
  938.  
  939. struct Data {
  940.   /*
  941.    * Allocated at fplInit() and freed at fplFree().
  942.    */
  943. #ifdef AMIGA
  944.   uchar *stack_base;    /* our new stack base */
  945.   long stack_size;    /* requested stack size! */
  946.   long stack_max;    /* Maximum stack left after a FPL function call */
  947.   long stack_limit;    /* absolute maximum stack usage allowed */
  948.   long stack_margin;    /* minimum stack required to call the interface
  949.                function! */
  950.   long registers[11];    /* Storage for the eleven registers that should be
  951.                brought back when calling the interface function */
  952.   struct Task *task;    /* pointer to our task! */
  953.   uchar *old_topstack;   /* previous top stack in the task struct */
  954.   uchar *old_botstack;   /* previous bot stack in the task struct */
  955.   long extern_stack;    /* external stack pointer */
  956.   long intern_stack;    /* internal stack pointer */
  957.   struct FuncList *funclibs; /* a linked list with the current opened funclib
  958.                                 names */
  959. #endif
  960.   /* --------------------------------------------------------------------- */
  961.   /* If anything is changed among the above, check validity of liballoc.i! */
  962.   /* --------------------------------------------------------------------- */
  963.  
  964.   void * ASM (*Alloc)(DREG(0) long,
  965.                       AREG(0) void *);  /* allocate routine to use */
  966.   void ASM (*Dealloc)(AREG(1) void *,
  967.                       DREG(0) long,
  968.                       AREG(0) void *); /* dealloc routine */
  969.  
  970.   long ASM (*function) (AREG(0) void *); /* Pointer to function handler. */
  971.   long ASM (*interfunc) (AREG(0) void *); /* Function to be called every now
  972.                          and then when executing, enabling
  973.                          your programming to keep track of
  974.                          different things even if FPL is in
  975.                          charge! */
  976.  
  977.   /********* START OF STORE STRUCT ***********/
  978.   
  979.   uchar *text;       /* Current interpret position */
  980.   long prg;         /* Current line number */
  981.   uchar *virfile;    /* virtual file name pointer */
  982.   long virprg;        /* virtual line number */
  983.  
  984.   uchar strret;        /* The Script() now executing should return a
  985.                string! (TRUE/FALSE) */
  986.   long level;        /* Nesting level */
  987.   long varlevel;    /* current variable level */
  988.  
  989.   uchar *interpret;  /* if we whould interpret anything else but the main
  990.                function! Set this with the FPLTAG_INTERPRET tag. */
  991.  
  992.   struct Local *globals; /* Pointer to list holding all global symbols
  993.                 currently declared in this program. They might be
  994.                 removed when this program quits if the user has
  995.                 set that flag or if we miss certain information */
  996.  
  997.   struct fplMsg *msg; /* Pointer to any pending message to FPL sent from the
  998.              user. We expect return codes from user functions to
  999.              be sent using this. */
  1000.  
  1001.   struct Program *prog; /* Pointer to the "struct Program" holding information
  1002.                about the program we're currently interpreting */
  1003.  
  1004.   struct Local *locals; /* Linked list of local variables! If any error
  1005.                code is returned, there might be local variables
  1006.                left to free in any precious local level! Use this
  1007.                list to delete 'em all!
  1008.                
  1009.                We add *ALL* levels to one list, separated with a
  1010.                NULL name. Deleting only the latest level, deletes
  1011.                to the nearest NULL name!
  1012.                */
  1013.  
  1014.   /********* END OF STORE STRUCT *************/
  1015.  
  1016.   struct Program *programs; /* list with all files information */
  1017.   long ret;        /* Return value of the FPL block */
  1018.   uchar *buf;        /* Global buffer pointer (Why use more than one buffer
  1019.                at a time? It's only a waste of valuable stack!) */
  1020.   void *userdata;       /* Global Userdata. Free to use. */
  1021.   unsigned long flags;  /* Flags. See defines below! */
  1022.   long data;            /* The result of the interfunc. */
  1023.   long FPLret;            /* FPL return code = the result of the
  1024.                "exit(RETURN_CODE);" call! */
  1025.   long *returnint;    /* pointer to the above if an integer actually was
  1026.                            returned */
  1027.   long hash_size;    /* hash table size! */
  1028.   struct Identifier **hash;  /* Must be set to NULL before doing anything
  1029.                 major... like using fplAddFunction() or
  1030.                 calling fplExecute[File]() The NULL-setting is
  1031.                 done by fplInit(). */
  1032.  
  1033.   struct Local *usersym; /* Pointer to list holding all global symbols
  1034.                 declared in another FPL program run. These symbols
  1035.                 are legal global symbols */
  1036.   
  1037.   struct MemInfo *MallocKey[2]; /* We have two mallockey pointers because we
  1038.                    have two different kinds of Malloc()s! One
  1039.                    for each execution and one for each
  1040.                    fplInit(). */
  1041.   struct FreeBlock *blox[BLOCK_ENTRIES]; /* memory caching tables */
  1042.   long blockcount[BLOCK_ENTRIES]; /* memory caching table counters */
  1043.   struct Identifier *func; /* pointer to the current interpreted function
  1044.                   or NULL */
  1045.   long runs;
  1046.   uchar **string_return;  /* whether this program should allow strings to be
  1047.                 returned to the host program (set with the
  1048.                 FPLTAG_STRING_RETURN tag to 'fplExecuteXXX()'). */
  1049.   uchar *identifier;    /* host program identifier. This should point to
  1050.                  a unique string to enable separation between
  1051.                  different processes use of FPL library functions! */
  1052.   void *debugentry;    /* used by the debugger alone! *Hands off!* */
  1053.   uchar *error;          /* pointer to error message buffer or NULL */
  1054.  
  1055.   long breaks; /* number of levels possible to break! Each nested for, do,
  1056.                   while and switch increases, each end of the same decreases
  1057.                   as well as break, return and exit */
  1058.  
  1059. #define ADDBUFFER_SIZE 32 /* buffered size; before appending string */
  1060.  
  1061.   uchar addchar_buffer[ADDBUFFER_SIZE];
  1062.   long addchar_len;
  1063. #ifdef AMIGA
  1064.   struct Library *FPLBase; /*
  1065.                             * Pointer to our own library base.
  1066.                             * Could become handy for the debugger and/or other
  1067.                             * external programs to control FPL internal
  1068.                             * affairs!!
  1069.                             */
  1070. #endif                             
  1071.  
  1072.   struct CompiledInfo localinfo;   /* local symbol list */
  1073.   struct CompiledInfo *globalinfo; /* global symbol list, points to the
  1074.                                       corresponding struct in the appropriate
  1075.                                       struct Program */
  1076.   struct fplArgument *arg; /* argument info since last function invoke */
  1077. };
  1078.  
  1079. /***** Data.flags: *****/
  1080.  
  1081. #define FPLDATA_ALLFUNCTIONS (1<<0)
  1082. /* Accept all functions, even if not found! */
  1083.  
  1084. #define FPLDATA_CACHEFILE (1<<1)
  1085. /* This file should be cached among the other global data. */
  1086.  
  1087. #define FPLDATA_CACHEALLFILES (1<<2)
  1088. /* This makes FPL store all files in memory that it has to remember */
  1089.  
  1090. #define FPLDATA_CACHEEXPORTS (1<<3)
  1091. /* This makes FPL store all files in memory that exports symbols */
  1092.  
  1093. #define FPLDATA_NESTED_COMMENTS (1<<6)
  1094. /* Allow nested comments */
  1095.  
  1096. #define FPLDATA_REREAD_CHANGES (1<<7)
  1097. /* Mark all files by default to get reread into memory when its accessed
  1098.    and the actual file is changed on disk, the symbols
  1099.    for that file will be removed and the file re-read into memory! */
  1100.  
  1101. #define FPLDATA_FLUSH_NOT_IN_USE (1<<8)
  1102. /* Mark all files by default to be flushed from memory when not used! */
  1103.  
  1104. #define FPLDATA_DEBUG_MODE (1<<9) /* currently running in debug mode! */
  1105. #define FPLDATA_DEBUG_GLOBAL (1<<10) /* always debug mode! */
  1106.  
  1107. #define FPLDATA_DEBUG (FPLDATA_DEBUG_MODE|FPLDATA_DEBUG_GLOBAL)
  1108.  
  1109. #define FPLDATA_KIDNAP_CACHED (1<<11) /* kidnap mode default */
  1110.  
  1111. #define FPLDATA_PREVENT_RUNNING_SAME (1<<12) /* never execute a file that is
  1112.                         cached and hasn't been changed
  1113.                         since last execution */
  1114.  
  1115. #define FPLDATA_ISOLATE (1<<13) /* this script cannot export symbols, nor
  1116.                                    can it access other exported symbols! */
  1117.  
  1118. #define FPLDATA_AUTOCOMPILE (1<<14)
  1119. #define FPLDATA_AUTORUN (1<<15)
  1120.                                    
  1121. struct fplMsg {
  1122.   struct fplMsg *next;  /* next message struct */
  1123.   struct fplMsg *prev;    /* when priority is allowed, things might be inserted
  1124.                virtually anywhere in the list */
  1125.   uchar type;        /* type of message. See defined below! */
  1126.   void *message[1];    /* different meanings depending on the type */
  1127.   uchar flags;        /* new from version 12.6 */
  1128. };
  1129.  
  1130. /* When the FPLMSG_RETURN type is used, these 'flags' bits tell which type
  1131.    that actually was returned! */
  1132. #define FPLMSG_FLG_STRING (1<<0)
  1133. #define FPLMSG_FLG_INT    (1<<1)
  1134. #define FPLMSG_FLG_BITS (FPLMSG_FLG_STRING | FPLMSG_FLG_INT)
  1135.  
  1136.  
  1137. #define FPLMSG_RETURN         1 /* general return type message, see the 'flags'
  1138.                    field for data type! */
  1139. #define FPLMSG_STOP          3 /* message[0] is to be stored in Data->data
  1140.                    as the "result of the last interfunc". */
  1141. #define FPLMSG_PROGRAM          4 /* message[0] is a (uchar **) to the program
  1142.                    array, message[1] is zero or the new number
  1143.                    of lines and message[2] is zero or the new
  1144.                    program size. */
  1145. #define FPLMSG_CONFIRM          5 /* message[0] is TRUE/FALSE */
  1146. #define FPLMSG_GLOBAL          6 /* Global symbol reading is ordered.
  1147.                    (FPLSEND_GLOBALSYMBOLS)
  1148.                    message[0] holds the current pointer to a
  1149.                    struct Local */
  1150.  
  1151.  
  1152. /**********************************************************************
  1153.  *                                                                    *
  1154.  * All functions used from external functions.                        *
  1155.  *                                                                    *
  1156.  **********************************************************************/
  1157.  
  1158. ReturnCode PREFIX fplExecuteScript(AREG(0) struct Data *,
  1159.                    AREG(1) uchar **,
  1160.                    DREG(1) long,
  1161.                    AREG(2) unsigned long *);
  1162. ReturnCode PREFIX fplExecuteFile(AREG(0) struct Data *,
  1163.                  AREG(1) uchar *,
  1164.                  AREG(2) unsigned long *);
  1165. uchar * PREFIX fplGetErrorMsg(AREG(0) struct Data *,
  1166.                  DREG(0) long,
  1167.                  AREG(1) uchar *);
  1168. void * ASM fplInit(AREG(0) long (*)(void *),
  1169.            AREG(1) unsigned long *);
  1170. void PREFIX fplFree(AREG(0) struct Data *);
  1171. ReturnCode PREFIX fplAddFunction(AREG(0) struct Data *,
  1172.                  AREG(1) uchar *,
  1173.                  DREG(0) long,
  1174.                  DREG(1) uchar,
  1175.                  AREG(2) uchar *,
  1176.                  AREG(3) unsigned long *);
  1177. ReturnCode PREFIX fplDelFunction(AREG(0) struct Data *,
  1178.                  AREG(1) uchar *);
  1179. ReturnCode PREFIX fplReset(AREG(0) struct Data *,
  1180.                AREG(1) unsigned long *);
  1181. ReturnCode PREFIX fplSend(AREG(0) struct Data *,
  1182.               AREG(1) unsigned long *);
  1183. void PREFIX *fplAlloc(AREG(0) struct Data *,
  1184.               DREG(0) long);
  1185. void PREFIX fplDealloc(AREG(0) struct Data *,
  1186.                AREG(1) void *);
  1187. void PREFIX *fplAlloca(AREG(0) struct Data *,
  1188.                DREG(0) long);
  1189. void PREFIX fplDealloca(AREG(0) struct Data *,
  1190.                 AREG(1) void *);
  1191. long PREFIX fplConvertString(AREG(0) struct Data *,
  1192.                  AREG(1) uchar *,
  1193.                  AREG(2) uchar *);
  1194. ReturnCode PREFIX fplCallFunction(AREG(0) struct Data *,
  1195.                   AREG(1) uchar *,
  1196.                   DREG(0) long,
  1197.                   AREG(2) void **,
  1198.                   AREG(3) uchar *format,
  1199.                   AREG(4) unsigned long *);
  1200.  
  1201. void PREFIX *fplAllocString(AREG(0) struct Data *,
  1202.                 DREG(0) long);
  1203. void PREFIX fplFreeString(AREG(0) struct Data *,
  1204.               AREG(1) void *);
  1205.  
  1206. #ifdef AMIGA
  1207. long PREFIX fplOpenLib(AREG(0) struct Data *,
  1208.                        AREG(1) uchar *,
  1209.                        DREG(0) long,
  1210.                        DREG(1) long);
  1211. long PREFIX fplCloseLib(AREG(0) struct Data *,
  1212.                         AREG(1) uchar *,
  1213.                         DREG(0) long);
  1214. #endif
  1215.  
  1216. ReturnCode PREFIX fplAddVariable(AREG(0) struct Data *,
  1217.                                  AREG(1) uchar *,
  1218.                                  DREG(0) long,
  1219.                                  DREG(1) uchar,
  1220.                                  AREG(2) void *,
  1221.                                  AREG(3) unsigned long *);
  1222.  
  1223. ReturnCode PREFIX fplReference(AREG(0) struct Data *,
  1224.                                AREG(1) struct Identifier *,
  1225.                                AREG(2) unsigned long *);
  1226.  
  1227. /**********************************************************************
  1228.  * All functions used globally in the library.                        *
  1229.  **********************************************************************/
  1230. /*
  1231.  * Mixed
  1232.  */
  1233.  
  1234. ReturnCode  REGARGS Expression(struct Expr *, struct Data *, long, struct Identifier *);
  1235. ReturnCode  REGARGS Eat(struct Data *);
  1236. ReturnCode  REGARGS Getword(struct Data *);
  1237.  
  1238. uchar * REGARGS GetErrorMsg(struct Data *, long, uchar *);
  1239.  
  1240. #ifdef UNIX
  1241. /* The Amiga version has this function coded in assembler */
  1242. long InterfaceCall(struct Data *, void *, long (*)(void *));
  1243. #define InterfaceCallNoStack InterfaceCall /* make them call the same func */
  1244. #endif
  1245.  
  1246. ReturnCode REGARGS DelProgram(struct Data *, struct Program *);
  1247. ReturnCode REGARGS ReadFile(void *, uchar *, struct Program *);
  1248. ReturnCode REGARGS Newline(struct Data *);
  1249. long REGARGS Strtol(uchar *, long, uchar **);
  1250.  
  1251. ReturnCode REGARGS NewMember(struct Data *, struct Expr **);
  1252. ReturnCode REGARGS ReturnChar(struct Data *, long *, uchar);
  1253. ReturnCode REGARGS GetEnd(struct Data *, uchar, uchar, uchar);
  1254. ReturnCode REGARGS CmpAssign(struct Data *, long, long *, long, uchar);
  1255. ReturnCode REGARGS StrAssign(struct fplStr *, struct Data *, struct fplStr **, uchar);
  1256. ReturnCode REGARGS AppendStringToString(struct Data *, struct fplStr **,
  1257.                     uchar *, long);
  1258. ReturnCode REGARGS Send(struct Data *, unsigned long *);
  1259. ReturnCode REGARGS GetProgram(struct Data *, struct Program *);
  1260. ReturnCode REGARGS LeaveProgram(struct Data *, struct Program *);
  1261. ReturnCode REGARGS Warn(struct Data *, ReturnCode);
  1262.  
  1263. ReturnCode REGARGS DeleteMessage(struct Data *, struct fplMsg *);
  1264. ReturnCode REGARGS GetMessage(struct Data *, uchar, struct fplMsg **);
  1265. ReturnCode REGARGS functions(struct fplArgument *);
  1266.  
  1267. /*
  1268.  * From script.c
  1269.  */
  1270. ReturnCode ASM Script(AREG(2) struct Data *,
  1271.                       AREG(3) struct Expr *,
  1272.                       DREG(2) short,
  1273.                       AREG(1) struct Condition *);
  1274. ReturnCode REGARGS ArrayResize(struct Data *, long, long *,
  1275.                                struct Identifier *);
  1276. void REGARGS CleanUp(struct Data *, long, long);
  1277. long REGARGS BitToggle(long, long, long);
  1278.  
  1279. /*
  1280.  * From memory.c
  1281.  */
  1282. void ASM *DefaultAlloc(DREG(0) long, AREG(0) void *);
  1283. void ASM DefaultDealloc(AREG(1) void *, DREG(0) long, AREG(0) void *);
  1284. uchar REGARGS TypeMem(void *);
  1285. void REGARGS SwapMem(struct Data *, void *, uchar);
  1286. void ASM Free(AREG(0) struct Data *, AREG(1) void *, DREG(0) uchar);
  1287. void REGARGS FreeCycle(struct Data *, void *);
  1288. void REGARGS FreeAll(struct Data *, uchar);
  1289. void ASM *Malloc(AREG(0) struct Data *, DREG(0) long, DREG(1) uchar DEBUGPARAMETERS1);
  1290. void *MallocCycle(struct Data *, long DEBUGPARAMETERS2);
  1291. void REGARGS InitFree(struct Data *);
  1292. void REGARGS FlushFree(struct Data *);
  1293. void REGARGS FreeKind(struct Data *, void *);
  1294. #ifdef DEBUG
  1295. ReturnCode REGARGS CheckMem(struct Data *, void *);
  1296. #endif
  1297. /*
  1298.  * From hash.c
  1299.  */
  1300. ReturnCode REGARGS AddToList(struct Data *, struct Identifier *,
  1301.                              struct Local **);
  1302. ReturnCode REGARGS AddVar(struct Data *, struct Identifier *, struct Local **);
  1303. ReturnCode REGARGS DelLocalVar(struct Data *, struct Local **);
  1304. ReturnCode REGARGS AddLevel(struct Data *);
  1305. ReturnCode REGARGS RenameIdentifier(struct Data *,
  1306.                                     struct Identifier *, uchar *);
  1307. ReturnCode REGARGS GetIdentifier(struct Data *, uchar *, struct Identifier **);
  1308. ReturnCode REGARGS DelIdentifier(struct Data *, uchar *, struct Identifier *);
  1309. /*
  1310.  * From numexpr.c
  1311.  */
  1312. long REGARGS ArrayNum(long, long, long *, long *);
  1313. ReturnCode REGARGS AddUnary(struct Data *, struct Expr *, Operator);
  1314. ReturnCode REGARGS Calc(struct Data *, struct Expr *, struct Expr *);
  1315. void REGARGS Clean(struct Data *, struct Expr *);
  1316. ReturnCode REGARGS CallFunction(struct Data *, struct fplArgument *,
  1317.                         struct Identifier *);
  1318. /*
  1319.  * From scan.c
  1320.  */
  1321. ReturnCode REGARGS ScanForNext(struct Data *,
  1322.                                Operator); /* previous operator */
  1323. /*
  1324.  * From statement.c
  1325.  */
  1326. ReturnCode REGARGS StringExpr(struct Expr *, struct Data *);
  1327. long REGARGS my_memicmp(uchar *, uchar *, long);
  1328.  
  1329. /*
  1330.  * From sprintf.c
  1331.  */
  1332. ReturnCode REGARGS Sprintf(struct Data *, struct fplStr **, uchar *,
  1333.                            void **, uchar *, long);
  1334. ReturnCode REGARGS AddCharBuffer(struct Data *, struct fplStr **, long);
  1335. #define ADD_RESET -1 /* reset buffer */
  1336. #define ADD_FLUSH -2 /* flush buffer */
  1337. /*
  1338.  * From sscanf.c
  1339.  */
  1340. long Sscanf(struct Data *, uchar *, uchar *, long, void **, uchar *);
  1341.  
  1342. #if defined(AMIGA)
  1343.  /*
  1344.   * These are functions for funclibs only:
  1345.   */
  1346.  
  1347. ReturnCode REGARGS OpenLib(struct Data *, uchar *, long, long *, uchar);
  1348. ReturnCode REGARGS CloseLib(struct Data *, uchar *, long, long *);
  1349.  
  1350. #endif
  1351.  
  1352. /*
  1353.  * Compilation function prototypes.
  1354.  * From compile.c
  1355.  */
  1356. ReturnCode REGARGS SetupCompiled(struct Program *);
  1357. ReturnCode REGARGS CmpExpr(struct Expr *, struct Data *, long );
  1358. ReturnCode REGARGS CmpReset(struct Data *, long);
  1359. ReturnCode REGARGS AssignArg(struct Data *);
  1360. ReturnCode REGARGS CmpExport(struct Data *);
  1361. ReturnCode REGARGS CmpSwitch(struct Data *, struct Expr *);
  1362. ReturnCode REGARGS CmpBreak(struct Data *, struct Expr *);
  1363.  
  1364.